//
//  DatabaseMigrateStep1.m
//  Apps
//
//  Created by Kevin Chen on 2019/8/6.
//  Copyright © 2019 appscomm. All rights reserved.
//

#import "DatabaseMigrateStep1.h"
#import "DownloadRecord.h"

@implementation DatabaseMigrateStep1

//@synthesize stepProgress = _stepProgress;

//- (instancetype)init
//{
//    self = [super init];
//    if (self) {
//        _stepProgress = [NSProgress progressWithTotalUnitCount:1];
//    }
//    return self;
//}

- (void)goUpActionWithCurrentDBVersion:(NSInteger)version progressHandler:(void (^)(NSProgress * _Nonnull))progressHandler error:(NSError * _Nullable __autoreleasing *)error {
    
    NSProgress *pro = [NSProgress progressWithTotalUnitCount:1];
    
    if (version == self.completeVersion - 1) {
        LYDataBaseMigrationAction *action = [[LYDataBaseMigrationAction alloc] initWithDatabase:[LYDatabase database]];
        [action dropTableWithTableClasses:@[[Sleep class], [SleepPoint class]] error:error];
        [Sleep createTable];
        [SleepPoint createTable];
        
        [DownloadRecord deleteByConditionSql:@"1 = 1"];
        [pro setCompletedUnitCount:1];
        
        if (progressHandler) {
            progressHandler(pro);
        }
    }
    
}

- (void)goDownActionWithError:(NSError * _Nullable __autoreleasing *)error {
    
}

- (NSInteger)completeVersion {
    return 1;
}

@end
